<?php

// 检查环境 php扩展
if (!extension_loaded('redis')) {
    exit('<h2>php扩展未安装redis或未重启生效！</h2>');
}
if (!extension_loaded('fileinfo')) {
    exit('<h2>php扩展未安装fileinfo或未重启生效！</h2>');
}
if (!class_exists('Imagick')) {
    exit('<h2>php扩展未安装imagemagick或未重启生效！</h2>');
}
if (!extension_loaded('zip')) {
    exit('<h2>php扩展未安装zip或未重启生效！</h2>');
}
if (extension_loaded('Zend OPcache')) {
    exit('<h2>禁止安装php扩展opcache</h2>');
}
if (extension_loaded('Zend OPcache')) {
    exit('<h2>禁止安装php扩展opcache</h2>');
}
if (extension_loaded('xdebug')) {
    exit('<h2>禁止安装php扩展xdebug</h2>');
}

// 禁用函数
if (!function_exists('proc_open')) {
    exit('<h2>PHP函数：proc_open函数被禁用，请先去宝塔-php管理-禁用函数-删除</h2>');
}

if($_SERVER['SERVER_NAME'] != get_mini_domain()){
    global $__MINI_GLOBAL_PAYCODE_0__;
    if(!$__MINI_GLOBAL_PAYCODE_0__){
        exit('<h2>env文件配置的域名为：'.get_mini_domain().'，实际使用的域名为：'.$_SERVER['SERVER_NAME'].'，请两者保持一致（去宝塔后台-对应网站-删除多余的域名）</h2>');
    }
}

$mask_img = \App\Wen\Utils\Settings::get('app_upload_image_mask_img', '', true);
if(!_empty_($mask_img)){
    if(!file_exists(storage_path($mask_img))){
        if(\App\Wen\Utils\Settings::get('app_upload_image_mask_type', 0, true) == 1){
            exit('<h2>您后台配置了水印图片地址，但该地址的水印图片不存在，请手动放对应的图片到该地址：'.storage_path($mask_img).'</h2>');
        }
    }
}

global $__MINI_GLOBAL_TENANTS_ARR__;
foreach ($__MINI_GLOBAL_TENANTS_ARR__ as $tenant_id){
    if($tenant_id > 0){
        if(!file_exists(config_path('admin_'.$tenant_id.'.php'))){
            $f = fopen(config_path('admin_'.$tenant_id.'.php'), 'w');
            fwrite($f, '<?php'.' return __system__admin__config__('.$tenant_id.');');
            fclose($f);
        }

        foreach (['Administrator', 'Extension', 'ExtensionHistory', 'Permission', 'Role'] as $file_name){
            if(!file_exists(base_path('dcat/laravel-admin/src/Models/'.$file_name.'_'.$tenant_id.'.php'))){
                $content = file_get_contents(base_path('dcat/laravel-admin/src/Models/'.$file_name.'.php.templete'));
                $content = str_replace($file_name, $file_name.'_'.$tenant_id, $content);
                $f = fopen(base_path('dcat/laravel-admin/src/Models/'.$file_name.'_'.$tenant_id.'.php'), 'w');
                fwrite($f, $content);
                fclose($f);
            }
        }
    }
}








